from djangoutil import render_to_response
from monitor.models import Group, Senario, Server
from django.http import HttpResponseRedirect, HttpResponse
import time

def index(request, id):
	groups = Group.objects.all()
	return render_to_response('health.html', locals())

def show(request, id):
	senario_id, server_id = id.split('_')
	senario = Senario.objects.get(id=senario_id)
	logs = senario.senariolog_set.filter(server__id=server_id).order_by('-created_at')
	return render_to_response('healthlog.html', locals())

def check_group(request, id):
	group = Group.objects.get(id=id)
	group.check_all()
	return HttpResponseRedirect('/health')
	
def check_one(request, id):
	senario_id, server_id = id.split('_')
	senario = Senario.objects.get(id=senario_id)
	senario.check(Server.objects.get(id=server_id))
	
	return HttpResponseRedirect('/health')

def noti(request, id):
	return HttpResponse('OK')